<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo Yii::$app->name;?> 后台管理</title>
<?php $this->HeaderView(['slide']);?>

<script type="text/javascript" src="<?php echo $this->root_dir; ?>/static/common/js/jquery.tablednd.js"></script>
</head>
<script>
function jointable(action, field){
	var jointype = $('#joinwith-jointype-'+action+'-'+field).val();
	var table = $('#joinwith-table-'+action+'-'+field).val();
	var joinfield = $('#joinwith-joinfield-'+action+'-'+field).val();
	var field_val = $('#joinwith-field-'+action+'-'+field).val();
	var content = '<table width="100%" id="join-table">\n\
	<tr>\n\
	<td width="100">关联方式</td><td><input type="text" id="jointype" class="input-text" value="'+jointype+'"></td>\n\
	</tr>\n\
	<tr>\n\
	<td width="100">关联表</td><td><input type="text" id="table" class="input-text" value="'+table+'"></td>\n\
	</tr>\n\
	<tr>\n\
	<td width="100">关联字段</td><td><input type="text" id="joinfield" class="input-text" value="'+joinfield+'"></td>\n\
	</tr>\n\
	<tr>\n\
	<td>显示字段</td><td><input type="text" id="field" class="input-text" value="'+field_val+'"></td>\n\
	</tr>\n\
	';
	art.dialog({
    content: content,
    id: 'EF893L',
	 button: [
        {
            name: '确定',
            callback: function () {
				var jointype = $('#join-table #jointype').val();
				var table = $('#join-table #table').val();
				var joinfield = $('#join-table #joinfield').val();
				var field_val = $('#join-table #field').val();
				$('#joinwith-jointype-'+action+'-'+field).val(jointype);
                $('#joinwith-table-'+action+'-'+field).val(table);
				$('#joinwith-joinfield-'+action+'-'+field).val(joinfield);
				$('#joinwith-field-'+action+'-'+field).val(field_val);
				setTimeout(function(){
					return true;
				},500);
                //return false;
            },
            focus: true
        },
        {
            name: '取消'
        }
    ]
});
	
}
</script>
<body class="view_form" id="view_form_Model">

        <form class="view-form-form" method="post" action="<?php echo $this->context->getModelsActionUrl([$model->modelid ? 'update' : 'create', 'modelid'=>$model->modelid]);?>" enctype="multipart/form-data">
        <input type="hidden" id="catid" name="Models[modelid]" value="<?php echo $model->modelid;?>">
        <input type="hidden" id="type" name="Models[type]" value="<?php echo $model->type;?>">
                    <div class="slideTxtBox mtop-0">
        <div class="hd">
                    <ul>
                
                <li><a href="javascript:;"><span></span>基础信息</a></li>
                <?php if($model->modelid){?>
                <li><a href="javascript:;"><span></span>后台首页</a></li>
                <?php }?>

            </ul>
                </div>
        <div class="bd">
                    <ul>
            <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                   <tr>
                        <th valign="top" class="td-title"><label for="catid">模型名称：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="name" name="Models[name]" value="<?php echo $model->name;?>"></td>
                    </tr>

                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">数据库表名：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="tablename" name="Models[tablename]" value="<?php echo $model->tablename;?>" <?php echo $model->modelid ? ' readonly="readonly"' : ''?>> 不含表前缀</td>
                    </tr>

                    
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">描述：</label></th>
                        <td class="td-input">
                        <textarea style="width:400px; height:50px;" class="input-text textarea-text" name="Models[description]"><?php echo @$model->description;?></textarea>
                        </td>
                    </tr>
                        </tbody>
            </table>
            </ul>
            <?php if($model->modelid){?>
             <ul>
            <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">管理首页视图：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="index_template" name="Models[setting][index][views]" value="<?php echo @$model->setting['index']['views']?>"> 默认为：modelsform_index</td>
                    </tr>
                    <?php if($model->type == 'category'){ ?>
<tr>
                        <th valign="top" class="td-title"><label for="catid">AJAX加载分类：</label></th>
                        <td class="td-input">
                        <?php
						

echo submodule\widgets\SubmoduleWidget::widget(['viewPath'=>'switchbutton', 'options' => [
    'primarykey'=> 'id',
	'id'=> 'setting-index-ajax',
	'name'=> 'Models[setting][index][ajax]',
	'value'=> @$model->setting['index']['ajax'],
	'attributes'=> array_merge($model->attributes, array('id'=>$model->modelid)),
	'model'=> $model,
	'setting'=> ['defaultvalue'=>1]

]]);
?>
                        
                        </td>
                    </tr>
                <?php
            }
				//print_r($models['fields']);
				//exit;
				$listorder = isset($model->setting['index']['listorder']) ? $model->setting['index']['listorder'] : $models['fields'];
?>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">显示的字段：</label></th>
                        <td class="td-input">
                    <table class="view-index-list" id="setting-index" style="width:800px; margin-top:0; margin-bottom:0" border="0" cellspacing="0" cellpadding="0">

    <thead>
                    <tr>
                    <th style="width:150px; text-align:left" align="left">字段</th>
                    <th style="width:70px; text-align:left" align="left">是否显示</th>
                    <th align="left" style="width: auto; text-align:left">STYLE</th>
                    </tr>
                    </thead>

                        <?php
						foreach($fields  as $k=>$v){
							if (!is_array($v)){
								if (isset($models['fields'][$k])){
									$v = $models['fields'][$k];
								}else if (isset($models['fields'][$val])){
									$v = $models['fields'][$val];
								}
							}
							if (!$v) continue;
							if (!$v['enabled']) continue;
						?>
                    <tr>
                    <td onclick="jointable('list', '<?php echo $v['field']?>')"><?php echo $v['name']?>(<?php echo $v['field']?>)
                    <input type="text" class="hidden" id="joinwith-jointype-list-<?php echo $v['field']?>" name="Models[setting][index][joinwith][<?php echo $v['field']?>][jointype]" value="<?php echo @$model->setting['index']['joinwith'][$v['field']]['jointype']?>">
                    <input type="text" class="hidden" id="joinwith-joinfield-list-<?php echo $v['field']?>" name="Models[setting][index][joinwith][<?php echo $v['field']?>][joinfield]" value="<?php echo @$model->setting['index']['joinwith'][$v['field']]['joinfield']?>">
                    <input type="text" class="hidden" id="joinwith-table-list-<?php echo $v['field']?>"  name="Models[setting][index][joinwith][<?php echo $v['field']?>][table]" value="<?php echo @$model->setting['index']['joinwith'][$v['field']]['table']?>">
                    <input type="text" class="hidden" id="joinwith-field-list-<?php echo $v['field']?>" name="Models[setting][index][joinwith][<?php echo $v['field']?>][field]" value="<?php echo @$model->setting['index']['joinwith'][$v['field']]['field']?>">
                    
                    </td>
                    <td class="td-locked">
                    <input type="hidden" class="input-text" name="Models[setting][index][listorder][]" value="<?php echo $v['fieldid']?>">
<div onclick="change_switch(this, '');" id="btn-locked" class="locked-<?php echo @in_array($v['field'], $model->setting['index']['fields']) ? '1' : '0';?>"></div>
<input type="checkbox" class="hidden" value="<?php echo $v['field']?>" name="Models[setting][index][fields][]" <?php echo @in_array($v['field'], $model->setting['index']['fields']) ? ' checked' : '';?> />
</td>
                    <td><textarea name="Models[setting][index][th][<?php echo $v['fieldid']?>]" class="textarea-text valid" style="width:95%; height:50px;"><?php echo @$model->setting['index']['th'][$v['fieldid']];?></textarea></td>
                    </tr>

                        <?php
						}
						?>

                        </table>
                        </td>
                    </tr>
  
                        </tbody>
            </table>
            </ul>
            <ul>
            <table class="view-form-input" id="setting-index" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    
<tr>
                        <th valign="top" class="td-title"><label for="catid">AJAX加载分类：</label></th>
                        <td class="td-input">

                        
                        </td>
                    </tr>


                                        <tr>
 
                        <th valign="top" class="td-title"><label for="catid"></label></th>
                        <td class="td-input"></td>
                    </tr>
               
  
                        </tbody>
            </table>
            </ul>
            <?php
			}
			?>
            
                </div>
    </div>
    <input type="submit" value="提交" name="sbmt" class="btn-submit mt-10" style="margin-left:120px">
<?=$this->csrfToken()?>

    </form>
<script type="text/javascript">
jQuery(".slideTxtBox").slide({trigger:"click"});
$(function(){
	$(".view-form-form").validate({	
		rules: {
			"Models[name]": {
				required: true,
			},
			"Models[tablename]": {
				required: true,
				remote: {
					url: "<?php echo $this->context->getModelsActionUrl(['check-tablename'])?>",     //后台处理程序
					type: "get",               //数据发送方式
					dataType: "json",           //接受数据格式   
					data: {  
					    modelid: '<?php echo $model->modelid?>',                   //要传递的数据
						tablename: function() {
							return $("#tablename").val();
						}
					}
			}
			}
		},
		messages: {
			"Models[name]": {
				required: '请输入模型名称',
			}
		}
	});
    $("#setting-index").tableDnD();	
	
});
</script> 
<?php $this->FooterView();?>
</body>
</html>
